$(function () {
    $("#jqGrid").Grid({
        url: '../tordercomment/list',
        colModel: [
			{label: 'id', name: 'id', index: 'id', key: true, hidden: true},
			// {label: '订单编号', name: 'orderNo', index: 'order_no', width: 80},
			// {label: '用户编号', name: 'userId', index: 'user_id', width: 80},
			// {label: '商品编号', name: 'proId', index: 'pro_id', width: 80},
			{label: '用户名称', name: 'username', index: 'username', width: 80,align:'center'},
			{label: '用户头像', name: 'logo', index: 'logo', width: 80,align:'center',
				formatter:function (value) {
					if (value != null) {
						return transImg(value);
					}
					return '';
				}
			},
			// {label: '商品名称', name: 'proName', index: 'pro_name', width: 80},
			{label: '商品图片', name: 'proUrl', index: 'pro_url', width: 80,align:'center',
				formatter:function (value) {
					if (value != null) {
						return transImg(value);
					}
					return '';
				}
			},
			// {label: '款式编号', name: 'styleId', index: 'style_id', width: 80},
			{label: '款式名称', name: 'styleName', index: 'style_name', width: 80,align:'center'},
			{label: '款式图片', name: 'styleUrl', index: 'style_url', width: 80,align:'center',
				formatter:function (value) {
					if (value != null)
					{
					                return transImg(value);
					 }
						                return '';
				}
			},
			// {label: '数量', name: 'number', index: 'number', width: 80},
			// {label: '价格', name: 'price', index: 'price', width: 80},
			// {label: '评论图片', name: 'commentImg', index: 'comment_img', width: 80},
			{label: '评论内容', name: 'content', index: 'content', width: 80},
			{label: '显示状态', name: 'statu', index: 'statu', width: 80,
				formatter:function (value) {
					if(value=="0"){
						return "隐藏";
					}
					if(value==""){
						return "显示";
					}
				}
			},
			{label: '创建时间', name: 'createDate', index: 'create_date', width: 80,
				formatter:function (value) {
					return transDate(value);
				}
			}]
    });
    // vm.queryProductList();
	vm.queryAllMerchantList();
});

let vm = new Vue({
	el: '#rrapp',
	data: {
        showList: true,
        title: null,
		tOrderComment: {},
		merchantList:[],
		productList:[],
		ruleValidate: {
			name: [
				{required: true, message: '名称不能为空', trigger: 'blur'}
			]
		},
		q: {
		    name: '',
			merchantId:'',
			proId:''
		}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function () {
			vm.showList = false;
			vm.title = "新增";
			vm.tOrderComment = {};
		},
		update: function (event) {
            let id = getSelectedRow("#jqGrid");
			if (id == null) {
				return;
			}
			vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
            let url = vm.tOrderComment.id == null ? "../tordercomment/save" : "../tordercomment/update";
            Ajax.request({
			    url: url,
                params: JSON.stringify(vm.tOrderComment),
                type: "POST",
			    contentType: "application/json",
                successCallback: function (r) {
                    alert('操作成功', function (index) {
                        vm.reload();
                    });
                }
			});
		},
		del: function (event) {
            let ids = getSelectedRows("#jqGrid");
			if (ids == null){
				return;
			}

			confirm('确定要隐藏选中的评论？', function () {
                Ajax.request({
				    url: "../tordercomment/delete",
                    params: JSON.stringify(ids),
                    type: "POST",
				    contentType: "application/json",
                    successCallback: function () {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
					}
				});
			});
		},
		getInfo: function(id){
            Ajax.request({
				url: "../tordercomment/info/"+id,
				async: true,
				successCallback: function (r) {
					vm.tOrderComment = r.tOrderComment;
				}
			});
		},
		reload: function (event) {
			vm.showList = true;
            let page = $("#jqGrid").jqGrid('getGridParam', 'page');
			$("#jqGrid").jqGrid('setGridParam', {
                postData: {'proId': vm.q.proId},
                page: page
            }).trigger("reloadGrid");
            vm.handleReset('formValidate');
		},
        reloadSearch: function() {
            vm.q = {
				proId: ''
            }
            vm.reload();
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        handleReset: function (name) {
            handleResetForm(this, name);
        },queryAllMerchantList:function () {
			Ajax.request({
				url: "../tordercomment/queryMerchantList",
				async: true,
				successCallback: function (r) {
					vm.merchantList = r.list;
				}
			});
		},queryProductList:function () {
			Ajax.request({
				url: "../tordercomment/queryPorductList?merchantId="+vm.q.merchantId,
				async: true,
				successCallback: function (r) {
					vm.productList = r.list;
				}
			});
		}
	}
});